home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group98c.txt / 000027_icon-group-sender _Tue Sep 15 09:00:17 1998.msg < prev    next >
Internet Message Format  |  2000-09-20  |  3KB

  1. Return-Path: <icon-group-sender>
  2. Received: from kingfisher.CS.Arizona.EDU (kingfisher.CS.Arizona.EDU [192.12.69.239])
  3.     by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) with SMTP id JAA00801
  4.     for <icon-group-addresses@baskerville.CS.Arizona.EDU>; Tue, 15 Sep 1998 09:00:17 -0700 (MST)
  5. Received: by kingfisher.CS.Arizona.EDU (5.65v4.0/1.1.8.2/08Nov94-0446PM)
  6.     id AA03129; Tue, 15 Sep 1998 08:59:49 -0700
  7. Date: Mon, 14 Sep 1998 21:52:44 -0400 (EDT)
  8. From: cwills@bix.com
  9. Subject: RE: Context Switching
  10. To: icon-group@optima.CS.Arizona.EDU
  11. Message-Id: <9809142152.memo.74091@BIX.com>
  12. X-Cosy-To: icon-group@optima.CS.Arizona.EDU
  13. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  14. Status: RO
  15.  
  16. Yes.. it really does require a seperate "thread" of execution.  The
  17. coswitch routine (the assembler code used for doing the context switch)
  18. replaces the C stack frame with a different stack frame then re-invokes
  19. the interepreter code.  Note that this is not a "whole seperate executable"
  20. but preserving the current dynamic set of variables while the co-routine
  21. is running.
  22.  
  23. Also note that if you dig deep enough into co-processes (co-routines and
  24. co-expressions) you will find that this is what is really going on under
  25. the covers.
  26.  
  27. The algorithm used by Icon expressed in a C-ish pseudeo code is:
  28.  
  29. coswitch( old_cs, new_cs, first )
  30. int *old_cs, *new_cs, first;
  31. {
  32.     /* save SP, frame pointers, and other registers in old_cs */
  33.     if ( first == 0 )
  34.     {
  35.         /* load sp from new_sp[0] and clear frame pointers */
  36.         interp( 0, 0 );
  37.         syserr( "interp() returned in coswitch" );
  38.     }
  39.     else
  40.     {
  41.         /* load sp, frame pointers and other registers from new_cs */
  42.     }
  43. }
  44. ---------
  45.  
  46. To implement the coswitch function using threads, one would have
  47. to locate where coswitch is called, change the allocation of the 
  48. co-expression stack to a creation of a thread that immediately blocks
  49. on a semaphore defined in the co-expression block.
  50.  
  51. Coswitch then would be passed the current co-expression's semaphore
  52. and the co-expression's semaphore to swap to, "post" the called semaphore
  53. and wait on the calling semaphore (if any of that makes sense).
  54.  
  55. Taking this alittle further, one might want to have a "master" thread
  56. (the original thread created by the system) and then when &main is created
  57. create a new thread for &main.  This would allow &main to be "destroyed"
  58. and still have the "master" thread always there.  The master thread could
  59. be used as a syncronizer if for some reason the OS needed stuff created
  60. by a parent thread.  If done correctly, co-expressions could actually
  61. be executed in parallel (have the master thread perform all memory 
  62. allocations, GC, file, etc).
  63.  
  64. Cheyenne
  65.